package com.zhizuobiao.exception;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ExceptionResolver implements HandlerExceptionResolver {
    public ModelAndView resolveException(HttpServletRequest httpServletRequest,
                                         HttpServletResponse httpServletResponse, Object o, Exception e) {

        System.out.println("统一处理异常位置");

        if (e instanceof MyException) {
            System.out.println("跳转到网络连接错误页面");
        } else if (e instanceof NullPointerException) {
            System.out.println("跳转到请稍后再试");
        } else if (e instanceof NullPointerException) {
            System.out.println("跳转到商品已下架");
        } else {
            System.out.println("请再试打开");
        }


        ModelAndView mv = new ModelAndView();
        mv.setViewName("error");
        mv.addObject("errorMsg", "报错了");


        return mv;
    }
}
